﻿@page
@model FytSoa.Web.Pages.FytAdmin.Cms.ArticleModifyModel
@{
    ViewData["Title"] = "文章管理";
    Layout = "~/Pages/FytAdmin/_Layout.cshtml";
}
<div id="container">
    <form class="layui-form form-cus form-back" action="">
        <div class="panel-body">
            <div class="panel-addpic">
                <div class="text">基本属性</div>
                <div class="form-cur-wall">
                    <label>所属栏目：</label>
                    <div class="layui-input-block">
                        <select name="ColumnId" lay-verify="required" lay-search="">
                            <option value="0">父级</option>
                            @{
                                if (Model.ColumnList.Any())
                                {
                                    foreach (var item in Model.ColumnList)
                                    {
                                        if (item.Id == Model.Article.ColumnId)
                                        {
                                            <option selected="selected" value="@item.Id">@item.Title</option>
                                        }
                                        else
                                        {
                                            <option value="@item.Id">@item.Title</option>
                                        }
                                    }
                                }
                            }
                        </select>
                    </div>
                </div>
                <div class="form-cur-wall">
                    <label>作者：</label>
                    <div class="layui-input-block">
                        <input type="text" name="Author" value="@Model.Article.Author" placeholder="" maxlength="30" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="form-cur-wall">
                    <label>来源：</label>
                    <div class="layui-input-block">
                        <input type="text" name="Source" value="@Model.Article.Source" maxlength="40" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="form-cur-wall">
                    <label>更新时间</label>
                    <div class="layui-input-block">
                        <input type="text" id="EditDate" name="EditDate" value="@Model.Article.EditDate" maxlength="100" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <ul class="addpic-list clearfix">
                    <li>
                        <div class="add-photo default">
                            <input class="imgv" id="ImgUrl" name="ImgUrl" type="hidden" value="@Model.Article.ImgUrl">
                            <div class="select-newimg fyt-cloud @(!string.IsNullOrEmpty(Model.Article.ImgUrl)?"layui-hide":"")" data-text="ImgUrl" data-img="imgShow" data-type="form">
                                <i class="icon-addphote"></i>
                                <span>选择图片</span>
                            </div>
                            <div class="add-photo-wall @(!string.IsNullOrEmpty(Model.Article.ImgUrl)?"":"layui-hide")">
                                <img id="imgShow" src="@Model.Article.ImgUrl">
                                <div class="phote-edit">
                                    <a class="photo-tool fyt-cloud" data-text="ImgUrl" data-img="imgShow" data-type="form" href="javascript:void(0)"><i class="layui-icon layui-icon-edit"></i>更换</a>
                                    <a class="photo-tool last" href="javascript:void(0)" onclick="oc.deleteFile()"><i class="layui-icon layui-icon-delete"></i>删除</a>
                                </div>
                                <div class="cover">封面</div>
                            </div>
                        </div>
                    </li>
                </ul>
                <div class="form-cur-wall">
                    <label style="line-height:inherit;">内容属性：</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="Audit" @(Model.Article.Audit ? "checked=''" : "") lay-skin="primary" title="审核状态">
                        <input type="checkbox" name="IsTop" @(Model.Article.IsTop ? "checked=''" : "") lay-skin="primary" title="是否推荐">
                        <input type="checkbox" name="IsHot" @(Model.Article.IsHot ? "checked=''" : "") lay-skin="primary" title="是否热点">
                        <input type="checkbox" name="IsScroll" @(Model.Article.IsScroll ? "checked=''" : "") lay-skin="primary" title="是否滚动">
                        <input type="checkbox" name="IsSlide" @(Model.Article.IsSlide ? "checked=''" : "") lay-skin="primary" title="是否幻灯">
                        <input type="checkbox" name="IsComment" @(Model.Article.IsComment ? "checked=''" : "") lay-skin="primary" title="是否允许评论">
                        <input type="checkbox" name="IsRecyc" @(Model.Article.IsRecyc ? "checked=''" : "") lay-skin="primary" title="是否在回收站">
                    </div>
                </div>
                <div class="form-cur-wall layui-clear">
                    <label style="line-height:inherit;">发布平台：</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="like[IsWap]" @(Model.Article.IsWap ? "checked=''" : "") lay-skin="primary" title="是否手机站显示">
                    </div>
                </div>
                <div class="form-cur-wall layui-clear">
                    <label style="line-height:inherit;">权重：</label>
                    <div class="layui-input-block">
                        <div id="slideSort" style="top:8px;"></div>
                    </div>
                </div>
                <div class="text else">扩展属性</div>
                <div class="form-cur-wall">
                    <label>文章标签：</label>
                    <div class="layui-input-block">
                        <input type="text" name="Tag" value="@Model.Article.Tag" placeholder="" maxlength="100" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="form-cur-wall">
                    <label>转向连接：</label>
                    <div class="layui-input-block">
                        <input type="text" name="LinkUrl" value="@Model.Article.LinkUrl" placeholder="以http开头" maxlength="100" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="text else">点击量</div>
                <div class="form-cur-wall">
                    <label>总点击量</label>
                    <div class="layui-input-block">
                        <input type="number" name="Hits" value="@Model.Article.Hits" maxlength="50" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="form-cur-wall">
                    <label>月点击量</label>
                    <div class="layui-input-block">
                        <input type="number" name="MonthHits" value="@Model.Article.MonthHits" maxlength="50" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="form-cur-wall">
                    <label>周点击量</label>
                    <div class="layui-input-block">
                        <input type="number" name="WeedHits" value="@Model.Article.WeedHits" maxlength="50" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="form-cur-wall">
                    <label>日点击量</label>
                    <div class="layui-input-block">
                        <input type="number" name="DayHits" value="@Model.Article.DayHits" maxlength="50" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div style="height:50px;"></div>
            </div>
            <div class="layui-row">
                <div class="layui-form-item">
                    <label class="layui-form-label">文章标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="Title" value="@Model.Article.Title" maxlength="100" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">副标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="SubTitle" value="@Model.Article.SubTitle" maxlength="500" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-col-md6 layui-col-xs12">
                    <div class="layui-form-item">
                        <label class="layui-form-label">SEO关键词</label>
                        <div class="layui-input-block">
                            <textarea name="KeyWord" class="layui-textarea" style="min-height: 60px;" placeholder="SEO关键字，填写利于抓取，英文逗号分隔">@Model.Article.KeyWord</textarea>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md6 layui-col-xs12">
                    <div class="layui-form-item">
                        <label class="layui-form-label">SEO描述</label>
                        <div class="layui-input-block">
                            <textarea name="Summary" class="layui-textarea" style="min-height: 60px;" placeholder="SEO描述，填写利于抓取，最多200个字">@Model.Article.Summary</textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-row">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">文章内容</label>
                    <div class="layui-input-block">
                        <textarea id="Content" name="Content" placeholder="请输入内容" class="layui-textarea">@Html.Raw(Model.Article.Content)</textarea>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="submit" id="submit"><i class="layui-icon layui-icon-loading layui-icon layui-anim layui-anim-rotate layui-anim-loop layui-hide"></i>立即提交</button>
                    <button type="button" class="layui-btn layui-btn-primary btn-open-close">返回列表</button>
                </div>
            </div>
        </div>
        <input type="hidden" name="Id" id="Id" value="@Model.Article.Id" />
    </form>
    <script src="/themes/tinymce/tinymce.min.js"></script>
    <script src="/themes/tinymce/langs/zh_CN.js"></script>
    <script>
        var oc, os;
        tinymce.init({
            convert_urls: false,
            selector: '#Content',
            height: 400,
            plugins: 'print preview code searchreplace autolink directionality visualblocks visualchars fullscreen image link media codesample table charmap hr pagebreak nonbreaking anchor toc insertdatetime advlist lists textcolor wordcount imagetools contextmenu colorpicker textpattern help filemanager',
            toolbar: 'formatselect styleselect | bold italic forecolor backcolor | link filemanager | alignleft aligncenter alignright alignjustify  | numlist bullist outdent indent  | removeformat'
        });
        layui.config({
            base: '/themes/js/modules/'
        }).use(['layer', 'jquery', 'common', 'form', 'laydate', 'slider'], function () {
            var form = layui.form, $ = layui.jquery, laydate = layui.laydate, slider = layui.slider, sort =@Model.Article.Sort;
            os = layui.common;
           
            form.render();
            laydate.render({
                elem: '#EditDate'
                , theme: '#393D49'
                , type:'datetime'
            });
            $('.panel-addpic').css({ 'min-height': $(window).height() - 95 });
            var sliderIndex=slider.render({
                elem: '#slideSort'
                , input: true
                , change: function (value) {
                    sort = value;
                }
                , theme:'#409eff'
            });
            //赋值
            sliderIndex.setValue(@Model.Article.Sort);

            os.cloudFile();
            oc = {
                setContent(v) {
                    for (var i = 0; i < v.length; i++) {
                        var item = v[i];
                        var imgIndex = v.lastIndexOf('/');
                        var str = item.name.substring(imgIndex + 1, item.name.length);
                        if (os.isExtImage(item.name)) {
                            tinyMCE.editors[0].execCommand('mceInsertContent', false, '<p><img src="' + item.name + '" alt="' + str + '"/></p>')
                        } else {
                            tinyMCE.editors[0].execCommand('mceInsertContent', false, '<p style="padding:12px 20px;background-color: #edf3f5;"><a href="' + item.name + '" target="_blank" title="' + str + '">' + str + '</a></p>')
                        }
                    }
                },
                fileSave(v) {
                    $(".select-newimg").addClass('layui-hide');
                    $(".add-photo-wall").removeClass('layui-hide');
                    $('#ImgUrl').val(v);
                    $('#imgShow').attr('src',v);
                },
                deleteFile(){
                    $(".select-newimg").removeClass('layui-hide');
                    $(".add-photo-wall").addClass('layui-hide');
                    $('#ImgUrl').val('');
                    $('#imgShow').attr('src', '');
                }
            };

            //监听提交
            form.on('submit(submit)', function (data) {
                $('#submit').attr('disabled', true).find('i').removeClass('layui-hide');
                data.field.Content = tinyMCE.editors[0].getContent();
                var urls = "api/article/add";
                if ($("#Id").val()!=='0') {
                    urls = "api/article/edit";
                }
                data.field.Audit = data.field.Audit === 'on' ? true : false;
                data.field.IsTop = data.field.IsTop === 'on' ? true : false;
                data.field.IsHot = data.field.IsHot === 'on' ? true : false;
                data.field.IsScroll = data.field.IsScroll === 'on' ? true : false;
                data.field.IsSlide = data.field.IsSlide === 'on' ? true : false;
                data.field.IsComment = data.field.IsComment === 'on' ? true : false;
                data.field.IsWap = data.field.IsWap === 'on' ? true : false;
                data.field.IsRecyc = data.field.IsRecyc === 'on' ? true : false;
                data.field.Sort = sort;
                //os.log(data.field);
                os.ajax(urls, data.field, function (res) {
                    $('#submit').attr('disabled', false).find('i').addClass('layui-hide');
                    if (res.statusCode === 200) {
                        var $$ = parent.layui.jquery;
                        $$("#isSave").val('1');
                        os.success('保存成功~');
                        setTimeout(function () {
                            parent.active.closeCloumnModify();
                        }, 500);
                    }
                    else {
                        os.error(res.message);
                    }
                });
                return false;
            });
            $(".btn-open-close").on('click', function () {
                parent.active.closeCloumnModify();
            });
        });
    </script>
</div>